﻿<Window x:Class="WpfStudy.StudyDataTemplate"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:entity="clr-namespace:WpfStudy"
        Title="DataTemplate" Height="400" Width="550">
    <Window.Resources>
        <entity:EnumConvert x:Key="NameConverter"></entity:EnumConvert>
        <DataTemplate x:Key="custTemplate" >
            <Grid Margin="0" Background="White">
                <Border BorderThickness="1" BorderBrush="SteelBlue" Margin="5" CornerRadius="4"
                    Background="{Binding Path=Background,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem}}}">
                    <Grid Margin="3">
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <TextBlock FontWeight="Bold" Text="{Binding Name}"></TextBlock>
                        <TextBlock Grid.Row="1" Text="{Binding Address}"></TextBlock>
                    </Grid>
                </Border>
            </Grid>
            
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        <ListBox x:Name="lstCustomer" SnapsToDevicePixels="True" 
                 ItemTemplate="{StaticResource custTemplate}" HorizontalContentAlignment="Stretch">
            <ListBox.ItemContainerStyle>
                <Style>
                    <Setter Property="Control.Padding" Value="0"></Setter>
                    <Style.Triggers>
                        <Trigger Property="ListBoxItem.IsSelected" Value="True">
                            <Setter Property="ListBoxItem.Background" Value="DarkRed"></Setter>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>

    </Grid>
</Window>
